#!/usr/bin/python
# -*- coding: utf-8 -*-

# Generic Mock Class

class GenericMock(object):
    
    def __init__ (self):
        self.operation_ = []
        self.methods_ = {}
        self.properties_ = {}
        self.dnl_ = set([]) #DoNotLog

    def StubForTesting(self, name, method):
        self.methods_[name] = method

    def Property(self, name, value):
        self.properties_[name] = value

    def DoNotLog(self, fname):
        self.dnl_.add(fname)

    def __iter__(self):
        for i in self.operation_:
            yield i

    def __getitem__(self, key):
        return self.operation_[key]

    def __len__(self):
        return len(self.operation_)

    def __contains__(self, key):
        return key < len(self.operation_)

    def clear(self):
        self.operation_ = []

    def __getattr__(self, name):
        def GenericMethod(*args, **kargs):
            if name not in self.dnl_:
                self.operation_.append((name, args, kargs))
            if name in self.methods_:
                return self.methods_[name](*args, **kargs)

        if name not in self.properties_:
            return GenericMethod
        else:
            return self.properties_[name]

    def __eq__(self, other):
        if isinstance(other, list):
            return other == self.operation_
        else:
            return False

    def __str__(self):
        return '%s' % (self.operation_)

    def __repr__(self):
        return '%r' % (self.operation_)
        
